<?	/*
	// File:	index.php
	// Purpose:	Includes, Coordinate.
	// Creation:	2001-10-29
	// Author:	Felix <webmaster@can-host.com>
	*/
// Turn off default error reporting
//error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
ob_start();

//
// Start Page Load Counter
$start_load = doubleval(ereg_replace('^0\.([0-9]*) ([0-9]*)$','\\2.\\1',microtime()));

//
// include configuration & functions file & error handling

if (isset($cfg)/* && $cfg['httpd_mode'] == 'webcp'*/) {
	load_globals();
	// Set up error handling if in debug mode
	if ($cfg['debug']) {
		$tmp = 'errorHandler.inc.phps';
		include($tmp);
		$errorHandling =& new ErrorHandler('errorHandler.ini');
		if ($cfg['debug_context']) {
			$errorHandling->set_context('level', E_NOTICE_NONE);
		}
		if ($cfg['debug_console']) {
			$errorHandling->set_source('level', E_NOTICE_NONE);
		}
		if ($cfg['debug_logging']) {
			$errorHandling->set_logging('level', E_NOTICE_NONE);
			$errorHandling->set_logging('file_log', $cfg['debug_log']);
		}
	}
	// If using apache for frontend then
	//  we should include functions.inc.phps....
} else/*if (isset($cfg)$cfg['httpd_mode'] == 'apache')*/ {
	$tmp = "config.inc.php";
	include($tmp);

	$tmp = "functions.inc.phps";
	include($tmp);
	load_globals();
	// Set up error handling if in debug mode
	if ($cfg['debug']) {
		$tmp = 'errorHandler.inc.phps';
		include($tmp);
		$errorHandling =& new ErrorHandler('errorHandler.ini');
		if ($cfg['debug_context']) {
			$errorHandling->set_context('level', E_NOTICE_NONE);
		}
		if ($cfg['debug_console']) {
			$errorHandling->set_source('level', E_NOTICE_NONE);
		}
		if ($cfg['debug_logging']) {
			$errorHandling->set_logging('level', E_NOTICE_NONE);
			$errorHandling->set_logging('file_log', $cfg['debug_log']);
		}
	}
}

// If cfg is not set after trying to include the file then
//  do not continue - we must have certain config files to
//  do anything whatsoever!
if (!isset($cfg))
	return;

//
// Shoot out NO-CACHE to proxies
send_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
send_header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
send_header("Cache-Control: no-store, no-cache, must-revalidate");
send_header("Cache-Control: post-check=0, pre-check=0", false);
send_header("Pragma: no-cache");
// 'dynamic' GLOBAL vars declared.
GLOBAL $T, $userdata, $rx;

//
// Initialize certain general vars.
$T = array();
$userdata = array();
unset($personaldata);
unset($domaindata);
unset($resellerdata);
unset($error);
unset($notice);
//

//
// Include Initialization sequence: connect to db, authenticate, set default vars
$rcode = include("init.inc.phps");

//
// always load english file to prevent missing fields in other langs.
/*if (file_exists("lang/english.phps") AND $lang != 'english') {
	include("lang/english.phps");
}
if (isset($lang)) {
	// load appropriate language file.
	if (file_exists("lang/".$lang.".phps"))
		include("lang/".$lang.".phps");
	else {
		echo 'index.php :: Invalid $lang';
		return;
	}
}*/

if($lang != 'english') {
	load_cached_file('lang/english.phps', 'T');
}

if(file_exists('lang/'.$lang.'.phps'))
	load_cached_file('lang/'.$lang.'.phps', 'T');
else {
	echo 'index.php :: $lang is an invalid Language! Using English instead.';
	return;
}

// Check for and include local language file
$tmplang = explode("/",__FILE__);
array_pop($tmplang);array_pop($tmplang);
$tmplang = implode("/",$tmplang)."/lang.php";
if (file_exists($tmplang))
	include($tmplang);

// If the bookmark action is triggered, save/reset it.
if ($bookmark == "true") {
	// update database
	mysql_query("UPDATE users SET favorites = '$cp:$url:$number:$user' WHERE username='".$userdata['username']."'");

	// in case we are looking at user settings or user info, reset the data in memory
	$personaldata['favorites'] = "$cp:$url:$number:$user";

	// send a 'notice' to be echoed before the cp script
	$notice = $T['Bookmarked'];
}
elseif ($bookmark == "reset" AND $personaldata['username']) {
	// update database
	mysql_query("UPDATE users SET favorites = '' WHERE username='".$personaldata['username']."'");

	// Unset previous favorites in memory
	$personaldata['favorites'] = "";

	// send a 'notice' to be echoed before the cp script
	$notice = $T['Bookmark reset'];

}
// if there's a skin available use it
if (!$noskin) {
//
// include {TAGS} parser module
$rcode = include("parser.inc.phps");

//
// Dump to the browser
// If we had a {MAIN PAGE} (i.e not a frame), explode the skin to include the web-cp script
if (strpos($newskin,"{MAIN PAGE}")!==false) {
	// echo head of skin
	$newskin = explode("{MAIN PAGE}",$newskin);
	echo $newskin[0];

	// Echo notices from the backend (bookmark done)
	if ($notice && $webcp_tag && empty($data['failed'])){
		echo "<br><div align='center'>".$notice."</div>\n";
	}

	// Prep variables that may be needed by a hook
	$hookdata['_userdata'] = $userdata;
	$hookdata['_personaldata'] = $personaldata;
	$hookdata['_domaindata'] = $domaindata;
	$hookdata['_resellerdata'] = $resellerdata;
	$hookdata['_cp'] = $cp;
	$hookdata['_url'] = $url;
	$hookdata['_current_url'] = $current_url;


	if (isset($action)) {
		$hookdata['_action'] = $action;
	}
	if (isset($confirm)) {
		$hookdata['_confirm'] = $confirm;
	}

	if (is_array($data)) {
		$hookdata += $data;
	}

	//
		// if webcp cookie is set & we're not logging out, include cp script / show page. else show login screen
	if ($webcp_tag && empty($data['failed'])) {
		if (!file_exists($cp."/".$url.".phps")) {
			call_hook("web:$cp:$url", $hookdata);
		} else {
			// include & display cp script
			include($cp."/".$url.".phps");
		}
	} else {
		if (!empty($url) && file_exists($url.".inc.phps")) {
			include($url.".inc.phps");
		} else {
			include("login.inc.phps");
		}
	}


	// include skin tail
	$newskin = $newskin[1];
}
        if(isset($T['_charset'])) str_replace("{CHARSET}",$T['_charset'],$newskin);
        else str_replace("{CHARSET}","iso-8859-1",$newskin);
// Stop load timer and echo the result with the skin (MUST BE AT THE END OF THE PAGE)
$load_time = round(ereg_replace('^0\.([0-9]*) ([0-9]*)$','\\2.\\1',microtime()) - $start_load,3);
echo str_replace("{LOAD TIME}",$load_time,$newskin);
// DEBUG Dump
if (isset($dump)) {
	echo '<pre>';
	if ($dump == 'env') {
		echo "\$_POST:\n";
		print_r($_POST);
		echo "\n\n\$_POST:\n";
		print_r($_POST);
		echo "\n\n\$data:\n";
		print_r($data);
	}
	echo '</pre>';
}

// No skin available - just show script / panel
} else {
	// include & display cp script
	include($cp."/".$url.".phps");
}
// THE END
return;
?>
